<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script type='text/javascript' src='../js/vue.js'></script>

</head>

<body>
    <script>
        let data = {
            name: 'SONG',
            address: '广州'
        }
        // 创建一个监视实例对象，用于监视data变化
        const obs = new Observer(data)
        console.log(obs)

        // 准备一个实例对象
        let vm = {}
        vm._data = obs

        function Observer(obj) {
            // 汇总对象中所有属性形成一个数组
            const keys = Object.keys(obj)
            // 遍历
            keys.forEach((k) => {
                Object.defineProperty(this, k, {
                    get() {
                        return obj[k]
                    },
                    set(val) {
                        console.log('name被更改，')
                        obj[k] = val
                    }
                })
            })
        }

    </script>
</body>

</html>